import cv2
import utils
import mycv
import numpy as np

# img = cv2.imread('/media/fang/3441-913C/tsr/input/output/n00007_00002.bmp')
bgr, yuv = utils.yuv420sp2bgr('/media/fang/3441-913C/tsr/img/00034_0.yuv420sp', 300, 300)
bgr2 = bgr[:50, :100]
yuv2 = yuv[:50, :100]
y = yuv2[:, :, 0]
u = yuv2[:, :, 1]
v = yuv2[:, :, 2]
# cv2.imshow('bgr', bgr2)
# cv2.waitKey(0)
pass
# hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)

# 提取hsv中H通道数据
# h = hsv[:, :, 0].ravel()
#
# plt.hist(h, 180, [0, 180])
# plt.show()

# cv2.imshow("img", img)
#
# # HSV 的下界限
# lower_red = np.array([170,30,30])
# # HSV 的上界限
# upper_red = np.array([180,255,255])
#
# # 通过上下限提取范围内的掩模mask
# mask = cv2.inRange(hsv, lower_red, upper_red)
# r = img[:, :, 2]
# img[:, :, :2] = 0
# mask = np.zeros(img.shape[:2], dtype=np.uint8)
# for row in range(img.shape[0]):
#     for col in range(img.shape[1]):
#         mask[row, col] = mycv.pixel_is_red(img[row, col])
#         if mask[row, col]:
#             print("dddd")
# cv2.imshow("mask", mask)
cv2.imshow('img', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
cv2.cvtColor(p1, cv2.COLOR_BGR2HSV)